package com.ruoyi.edge.gateway.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.mybatis.core.page.PageQuery;
import com.ruoyi.common.mybatis.core.page.TableDataInfo;
import com.ruoyi.edge.gateway.domain.EquipmentTask;
import com.ruoyi.edge.gateway.mapper.EquipmentTaskMapper;
import com.ruoyi.edge.gateway.service.EquipmentTaskService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 边缘计算设备数据解析任务
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class EquipmentTaskServiceImpl implements EquipmentTaskService {

    private final EquipmentTaskMapper equipmentTaskMapper;

    @Override
    public TableDataInfo<EquipmentTask> listPage(EquipmentTask equipmentTask, PageQuery pageQuery) {

        LambdaQueryWrapper<EquipmentTask> lqw = new LambdaQueryWrapper<>();
        Page<EquipmentTask> page = equipmentTaskMapper.selectPage(pageQuery.build(), lqw);
        return TableDataInfo.build(page);
    }

    @Override
    public R<EquipmentTask> get(String id) {
        EquipmentTask equipmentTask = equipmentTaskMapper.selectById(id);
        return R.ok(equipmentTask);
    }

    @Override
    public R<String> add(EquipmentTask equipmentTask) {
        equipmentTaskMapper.insert(equipmentTask);
        return R.ok("新增成功");
    }

    @Override
    public R<String> edit(EquipmentTask equipmentTask) {
        equipmentTaskMapper.updateById(equipmentTask);
        return R.ok("修改成功");
    }

    @Override
    public R<String> remove(String id) {
        equipmentTaskMapper.deleteById(id);
        return R.ok("删除成功");
    }

    @Override
    public R<String> editStatus(String id, Integer status) {
        equipmentTaskMapper.editStatus(id, status);
        return R.ok("修改成功");
    }

}
